<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="/WEB-INF/tlds/c.tld" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>编辑用户信息</title>
	<link rel="stylesheet" type="text/css" href="../css/index.css"></link>
	<script src="../js/common.js"></script>
	<script src="../js/jquery.plugins/jquery.js"></script>
	<link rel="stylesheet" type="text/css" href="../js/jquery.plugins/easyui/css/default/easyui.css"></link>
	<link rel="stylesheet" type="text/css" href="../js/jquery.plugins/easyui/css/icon.css"></link>
	<script src="../js/jquery.plugins/easyui/jquery.easyui.min.js"></script>
	<script src="../js/myvalidatebox.js"></script>
	<script src="../js/jquery.plugins/easyui/easyui-lang-zh_CN.js"></script>
	<script>
		$(function(){
			$('#saveBtn').linkbutton({iconCls:'icon-save',text:"保存",plain:true});
			$('#backBtn').linkbutton({iconCls:'icon-back',text:"返回上一页",plain:true});
			$('#resetBtn').linkbutton({iconCls:'icon-reload',text:"重置",plain:true});
			
			$("#name").validatebox( {
				required:true,
				validType:"length[2,32]",
				missingMessage:"名称不能为空",
				invalidMessage:"名称在2到32个字符以内。"
			});
			
			$(":checkbox[name=userGroups]").each(function(index,dom){
				var groups = [ ${model.groups} ];
				for(i=0;i<groups.length;i++){
					if( $(dom).val() == groups[i] ){
						$(dom).attr("checked" , true );
					}
				}
			});
		
			$("#companyId").validatebox( {required:true,missingMessage:"请选择所属店铺"});
			$("#departmentId").validatebox( {required:true,missingMessage:"请选择所属所属部门"});
			$("#password").validatebox( {validType:"length[6,16]",invalidMessage:"密码在6到16个字符以内。"});
			$("#repassword").validatebox( {validType:"same['password']",invalidMessage:"确认密码与密码不匹配。"});
			$("#email").validatebox( {validType:'emailandlength[0,64]',invalidMessage:'请输入正确的邮件格式,并且长度不超过64位'});
			$("#tel").validatebox( {validType:'length[0,32]'});
			$("#mobile").validatebox( {validType:'length[0,32]'});
			$("#address").validatebox( {validType:'length[0,256]'});
			$("#memo").validatebox( {validType:"length[0,256]",invalidMessage:"描述在0到256个字符以内。"});
			
			$("form").submit(function(){
					return checkValidate(["name" , "password" , "repassword", 
						"companyId" ,"email" , "tel" , "mobile","address" , "departmentId" , "memo"]);
				}	
			);
		});
		function findDepartment( companyId ){
			if( companyId == 0 ){
				fillSelect( "departmentId" );
				return false;
			}
			var param = "companyId=" + companyId;
			jsonSend("/department/ajaxFindByCompany.ht",param,function(departments){
					fillSelect( "departmentId" , departments, "id","name" ,"请选择部门...");
				});
		}
		function checkSame(){
			if( $.trim( $("#name").val() ) == "" ){
				$.messager.alert( '提示','还没有填写姓名!','info');
				return;
			}
			var param = "name=" + $.trim( $("#name").val() ) + "&id=" + $("#id").val();
			jsonSend("check.ht",param,function(flag){
				if( flag )
					errorMsg( "提示","该姓名重复" );
				else
					infoMsg( "提示","该姓名不重复" );
			});
		}
	</script>
</head>
<body>
	<!-- 导航部分 -->
	<div class="position">
	您当前的位置：系统管理 &gt;&gt; <a href="list.ht">用户信息管理</a> &gt;&gt; 编辑用户信息
	</div>
	<!-- 导航部分结束 -->
	<!-- 表单部分开始 -->
	<div>
		<form action="save.ht" method="post">
			<input type="hidden" name="id" id="id" value="${model.id}"/>
			<table class="form" style="width:50%;">
				<tr>
					<td class="title">姓名(登陆名)：</td>
					<td><input type="text" style="width:200px;"  id="name" name="name" value="${model.name }"/>
					<a href="#" onclick="checkSame();">检查姓名是否重复</a></td>
				</tr>
				<tr>
					<td class="title">登陆密码：</td>
					<td><input type="password" style="width:200px;"  id="password" name="password" value=""/>
					<c:if test="${model != null }"><font class="error">修改时不填默认为原密码</font></c:if>
					<c:if test="${model == null }"><font class="error">添加时不填默认为123456</font></c:if></td>
				</tr>
				<tr>
					<td class="title">确认密码：</td>
					<td><input type="password" style="width:200px;"  id="repassword" name="repassword" value=""/></td>
				</tr>
				<tr>
					<td class="title">启用状态：</td>
					<td>
						<input type="radio" name="status" value="true" <c:if test="${model.status==true || model == null}">checked</c:if>/>可以登陆
						<input type="radio" name="status" value="false" <c:if test="${model.status==false}">checked</c:if>/>禁止登陆
					</td>
				</tr>
				<tr>
					<td class="title">所属店铺：</td>
					<td><select name="companyId" id="companyId" style="width:400px;"  onchange="findDepartment( this.value );">
					<option value="">请选择店铺...</option>
						<c:forEach var="company" items="${companys}">
						<option value="${company.id}" <c:if test="${ company.id==model.companyId}">selected</c:if>><c:if test="${company.lev == 1}">&nbsp;&nbsp;</c:if>${company.name}</option>
						</c:forEach>
					</select></td>
				</tr>
				<tr>
					<td class="title">所属部门：</td>
					<td><select name="departmentId" id="departmentId" style="width:400px;">
					<option value="">请选择部门...</option>
						<c:forEach var="department" items="${departments}">
						<option value="${department.id}" <c:if test="${ department.id ==model.department.id }">selected</c:if>>${department.name}</option>
						</c:forEach>
					</select></td>
				</tr>
				<tr>
					<td class="title">所属用户组：</td>
					<td>
						<c:forEach var="userGroup" items="${userGroups}"><input type="checkbox" name="userGroups" id="userGroups" value="${userGroup.id}"/>${userGroup.name}</c:forEach>
					</td>
				</tr>
				<tr>
					<td class="title">其他信息：</td>
					<td>
						<table class="form" style="width:95%;margin-bottom:5px;">
							<tr>
								<td class="title">email：</td>
								<td><input type="text" style="width:200px;"  id="email" name="email" value="${model.email }"/></td>
							</tr>
							<tr>
								<td class="title">电话：</td>
								<td><input type="text" style="width:200px;"  id="tel" name="tel" value="${model.tel }"/></td>
							</tr>
							<tr>
								<td class="title">手机：</td>
								<td><input type="text" style="width:200px;"  id="mobile" name="mobile" value="${model.mobile }"/></td>
							</tr>
							<tr>
								<td class="title">地址：</td>
								<td><input type="text" style="width:200px;"  id="address" name="address" value="${model.address }"/></td>
							</tr>
						</table>
					</td>
				</tr>
				
				<tr>
					<td class="title">简介：</td>
					<td><textarea id="memo" name="memo">${model.memo }</textarea></td>
				</tr>
				<tr>
					<td colspan="2" class="btntd">
					<a href="javascript:commit();" id="saveBtn">保存</a>
					<a href="javascript:reset();" id="resetBtn">重置</a>
					<a href="javascript:goBack();" id="backBtn">返回上一页</a>
					</td>
				</tr>
			</table>
		</form>
	</div>
	<!-- 表单部分结束  -->
</body>
</html>